package com.ydd.common.utils.excel.poi.poi;

import org.apache.poi.ss.usermodel.Workbook;
import java.util.*;

public class ExcelUtil {


    /***
     *
     * @param rowList 列名
     * @param list 数据，一个数据用一个map装，key装列名，val装值
     * @return Workbook
     * @throws Exception
     */
    public static Workbook excelUtil(List<String> rowList, List<Map<String, String>> list) throws Exception {
        //Collections.sort(rowList);
        Collections.sort(rowList, Comparator.comparing(s -> s.substring(0, 1)));
        //表头列名
        Map<String, String> map = new TreeMap<>();
        for (String row : rowList) {
            map.put(row, row);
        }

        List<Map<String, String>> titleList = new ArrayList<>();
        //放列名的
        titleList.add(map);
        //单级的 行内数据
        List<Map<String, String>> rowListDate = list;

        ExcelTool excelTool = new ExcelTool("sheet1", 15, 20);
        //表头数据
        List<Column> titleData = excelTool.columnTransformer(titleList);

        Workbook workbook = excelTool.exportWorkbook(titleData, rowListDate, true);

        return workbook;
    }

}